//
//  MoreMaterialCell.m
//  CoachsBook
//
//  Created by MaBookPro on 2022/8/19.
//

#import "MoreMaterialCell.h"

@implementation MoreMaterialCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self creatcelllist];
    }
    return self;
}

-(void)creatcelllist{
    
    UIView *backV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APPwidth, 400)];
    backV.backgroundColor = [UIColor whiteColor];
    backV.userInteractionEnabled = YES;
    [self.contentView addSubview:backV];

    UIImageView *circleimgv = [[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 40, 40)];
    circleimgv.backgroundColor = [UIColor whiteColor];
    circleimgv.image = [UIImage imageNamed:@"headicon"];
    circleimgv.layer.cornerRadius = 40/2;
    //    circleimgv.userInteractionEnabled = YES;
    [backV addSubview:circleimgv];
    
    UILabel *nameLab = [[UILabel alloc]initWithFrame:CGRectMake(circleimgv.frame.size.width+circleimgv.frame.origin.x+10, 15, 60, 15)];
    nameLab.text = @"杜子腾";
    nameLab.textColor = [UIColor blackColor];
    nameLab.textAlignment = 0;
    nameLab.font = [UIFont systemFontOfSize:14 weight:bold];
    [backV addSubview:nameLab];
    
    
    UILabel *typeLab = [[UILabel alloc]initWithFrame:CGRectMake(nameLab.frame.size.width+nameLab.frame.origin.x+10,  12.5, 55, 20)];
    typeLab.text = @"未认证";
    typeLab.textColor = rgba(138, 138, 138, 1);
    typeLab.layer.backgroundColor = rgba(245, 245, 250, 1).CGColor;
    typeLab.textAlignment = 1;
    typeLab.layer.cornerRadius = 10;
    typeLab.font = [UIFont systemFontOfSize:12];
    [backV addSubview:typeLab];
    
    NSString *str = @"七”待已久“夕”望你来\n相约驾校约惠七夕\n今天报名享惊爆价\n两人组团报名更有优惠\n📞报名热线：18684930576\n";
    NSTextAttachment * attachment = [[NSTextAttachment alloc]init];
       //设置图片属性
       attachment.image = [UIImage imageNamed:@"AdmissionsImage"];
       //设置图片的bounds
       attachment.bounds = CGRectMake(0, 0, 120, 180);
       //将attachment转换成字符串属性
       NSMutableAttributedString *attachmentString = (NSMutableAttributedString *)[NSAttributedString attributedStringWithAttachment:attachment];
    
    NSTextStorage *storage = [NSTextStorage new];
       [storage replaceCharactersInRange:NSMakeRange(0, 0)
                              withString:
        str];
    // 给内容容器添加布局(可以添加多个)
      NSLayoutManager *layoutManager = [NSLayoutManager new];
      [storage addLayoutManager:layoutManager];
      // 带有内容和布局的容器
      NSTextContainer *textContainer = [NSTextContainer new];
      [layoutManager addTextContainer:textContainer];
      // 给_textView添加带有内容和布局的容器
      _textView = [[UITextView alloc] initWithFrame:CGRectMake(circleimgv.frame.size.width+circleimgv.frame.origin.x+10, nameLab.frame.size.height + nameLab.frame.origin.y+10, APPwidth-80, 300)textContainer:textContainer];
      _textView.scrollEnabled = NO;
      _textView.editable      = NO;
    _textView.userInteractionEnabled = YES;
      [backV addSubview:_textView];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_textView.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:5];
    [paragraphStyle setParagraphSpacing:2];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [_textView.text length])];
    _textView.attributedText = attributedString;
    [_textView.textStorage appendAttributedString:attachmentString];

    UILabel *peopleLab = [[UILabel alloc]initWithFrame:CGRectMake(circleimgv.frame.size.width+circleimgv.frame.origin.x+15,  _textView.frame.size.height + _textView.frame.origin.y+5, 120, 15)];
    peopleLab.text = @"80703人使用";
    peopleLab.textColor = rgba(138, 138, 138, 1);
    peopleLab.textAlignment = 0;
    peopleLab.font = [UIFont systemFontOfSize:12];
    [backV addSubview:peopleLab];


    NSArray *titilearr = @[@"复制文字",@"保持图文",@"转发朋友圈"];
    NSArray *picarr = @[@"copytitle",@"saveImage",@"friendcicle"];
    for (int i = 0; i < titilearr.count; i++) {
    UIButton *copytitlebtn = [[UIButton alloc]initWithFrame:CGRectMake(circleimgv.frame.size.width+circleimgv.frame.origin.x+100*i, peopleLab.frame.size.height+peopleLab.frame.origin.y+10,100, 15)];
    [copytitlebtn setTitle:titilearr[i] forState:0];
    [copytitlebtn setImage:[UIImage imageNamed: picarr[i]] forState:0];
    copytitlebtn.titleLabel.textAlignment = 0;
    copytitlebtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [copytitlebtn setTitleColor:[UIColor orangeColor] forState:0];
    copytitlebtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
    [copytitlebtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
    [backV addSubview:copytitlebtn];


    }
    
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, backV.frame.size.height-1, APPwidth, 1)];
    line.backgroundColor = rgba(245, 245, 250, 1);
    [backV addSubview:line];

    

}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
